<template>
	<view class="fillBox">
		<view class="title">数据填报</view>
		<!-- 填报内容 -->
		<view class="fillContent">
			<view class="fillContentBox">
				<view class="numType">
					<view class="numType1">数据类型:</view>
					<view class="numType2">店铺数据</view>
				</view>
				<view class="wire"></view>
				<view class="nameBox">
					<view class="nameBox1">线索:</view>
					<input type="text" v-model="form.name" class="nameBox2" placeholder="请输入线索" />
				</view>
				<view class="wire"></view>
				<view class="nameBox">
					<view class="nameBox1">A卡:</view>
					<input type="text" v-model="form.mobile" class="nameBox2" placeholder="请输入A卡" />
				</view>
				<view class="wire"></view>
				<view class="nameBoxa">
					<view class="nameBoxa1">订单:</view>
					<input type="text" v-model="form.cat_type" class="nameBoxa2" placeholder="请输入订单" />
				</view>
				<view class="wire"></view>
				<view class="nameBoxa">
					<view class="nameBoxa1">活动:</view>
					<view class="uni-list-cell-db" style="flex: 1;">
						<picker @change="bindPickerChange" :value="index" :range="array">
							<view class="uni-input" :class="index==''?'uni-inputs':'uni-inputa'" >{{index==''?'请选择活动':array[index] }}</view>
						</picker>
					</view>
				</view>
				<view class="wire"></view>
				<view class="remarks">
					<view class="remarks1">销售:</view>
					<textarea class="remarks2" v-model="form.remark" placeholder="请输入销售" />
				</view>
				<view class="wire"></view>
				<view class="btn" @click="submitClick">确定提交</view>
			</view>
		</view>
	</view>
</template>

<script>
import { fillIn, acttList } from '@/request/api.js';
export default {
	data() {
		return {
			form: {
				type: 2,
				name: '', //姓名
				mobile: '',
				cat_type: '', //购买车型
				remark: '',
				budget: '',
				distributor_id: '',
				regional_id: '',
				gender: 1,
				age: '',
				colour: '',
				purpose: '',
				activity_id: ''
			},
			index: '',
			array: [],
			arrayS: [],
			
		};
	},
	onLoad() {
		this.form.distributor_id = uni.getStorageSync('login').id;
		this.form.regional_id = uni.getStorageSync('login').regional_id;
	},
	onShow() {
		this.init();
	},
	methods: {
		init() {
			let _this = this
			acttList()
				.then(res => {
					
					if (res.code == 1) {
						_this.array = [];

						_this.arrayS = res.data;
						
						for (let i = 0; i < res.data.length; i++) {
							// console.log(res.data[i])
							_this.array.push(res.data[i].name);
						}

						// _this.arrayS.forEach((item, indexs) => {
						// 	if (itme.id == _this.mendianId) {
						// 		_this.index = indexs;
						// 	}
						// });
					}
				})
				.catch(err => {});
		},
		submitClick() {
			let _this = this;
			console.log(_this.index);
			
			if (_this.form.name == '' || _this.form.mobile == '' || _this.form.cat_type == '' || _this.form.remark == '' || _this.form.activity_id == '') {
				uni.showToast({
					title: '请填写完整信息',
					icon: 'none'
				});
				return;
			}
			fillIn(_this.form).then(res => {
				console.log(res);
				uni.showToast({
					title: res.msg,
					icon: 'none'
				});
				if (res.code == 1) {
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/DLR/dataManagement/dataManagement'
						});
					}, 2000);
				}
			});
		},
		bindPickerChange: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			let _this = this;
			this.index = e.target.value;
			this.arrayS.forEach((item, idnexs) => {
				if (e.target.value == idnexs) {
					_this.form.activity_id = item.id;
				}
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #ffffff;
}

.fillBox {
	width: 100%;
	box-sizing: border-box;
	padding-bottom: 40rpx;
	overflow: hidden;
	position: relative;
	.title {
		width: 100%;
		text-align: center;
		margin-top: 54rpx;
		font-size: 38rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #313233;
	}
	.fillContent {
		width: 100%;
		overflow: hidden;
		.fillContentBox {
			width: 622rpx;
			margin: 30rpx auto 0;
			.numType {
				width: 100%;
				display: flex;
				overflow: hidden;
				.numType1 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					min-width: 200rpx;
				}
				.numType2 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
				}
			}

			.wire {
				width: 100%;
				height: 4rpx;
				background-color: #e9e9ec;
				margin-top: 28rpx;
			}
			.nameBox {
				width: 100%;
				display: flex;
				overflow: hidden;
				margin-top: 40rpx;
				.nameBox1 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					min-width: 200rpx;
				}
				.nameBox2 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					flex: 1;
				}
			}
			.nameBoxa {
				width: 100%;
				display: flex;
				overflow: hidden;
				margin-top: 40rpx;
				.nameBoxa1 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					min-width: 200rpx;
				}
				.nameBoxa2 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					flex: 1;
				}
			}
			.remarks {
				width: 100%;
				display: flex;
				overflow: hidden;
				margin-top: 40rpx;
				.remarks1 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					// margin-right: 150rpx;
					min-width: 200rpx;
				}
				.remarks2 {
					width: 386rpx;
					height: 230rpx;
					padding: 10rpx;
					border: 1px solid #e9e9ec;
				}
			}
			.btn {
				width: 460rpx;
				height: 80rpx;
				background: #1855f6;
				border-radius: 40rpx;
				// margin-top: 122rpx;
				margin: 122rpx auto 0;
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ffffff;
				line-height: 80rpx;
				text-align: center;
			}
		}
	}
}
.uni-inputs{
font-size: 36rpx;
color: #888A88;
}
.uni-inputa{
	font-size: 36rpx;
}
</style>
